package executors.completable.future;

import java.util.concurrent.*;

public class SupplyAsyncTest002 {
  public static void main(String[] args) throws ExecutionException, InterruptedException {
    ExecutorService executors = Executors.newFixedThreadPool(2);
    
    // 可以传递两个参数  第二个参数是一个线程池
    CompletableFuture<String> integerCompletableFuture = CompletableFuture.supplyAsync(() -> {
      
      try {
        TimeUnit.SECONDS.sleep(1);
      } catch (InterruptedException e) {
        throw new RuntimeException(e);
      }
      System.out.println(Thread.currentThread().getName());
      return "ok";
    }, executors);
    
    System.out.println(integerCompletableFuture.get());
  }
}
